package cn.wangqi.personal.dao;

import cn.wangqi.personal.domain.BlogUser;
import cn.wangqi.personal.util.Page;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
/**
 * BlogUserDao
 *
 * @author wangqi
 * @date 2017/10/19
 */
public class BlogUserDao{
    private final String NAMESPACE = this.getClass().getName() + ".";
    private Logger logger = Logger.getLogger(BlogUserDao.class);
    @Resource
    protected SqlSessionTemplate mainSqlSession;

    public BlogUser findBlogUserByUserName(String userName){
        return mainSqlSession.selectOne(NAMESPACE + "findBlogUserByUserName", userName);
    }

    public void saveBlogUser(BlogUser blogUser) {
        mainSqlSession.insert(NAMESPACE + "saveBlogUser", blogUser);
    }



    public void saveBlogUser(List<BlogUser> blogUser) {
        mainSqlSession.insert(NAMESPACE + "saveBlogUserList", blogUser);
    }

    public void deleteBlogUserById(int blogUserId) {
        mainSqlSession.delete(NAMESPACE + "deleteBlogUserById", blogUserId);
    }

    public BlogUser findBlogUserById(int blogUserId){
        return mainSqlSession.selectOne(NAMESPACE + "findBlogUserById", blogUserId);
    }

    public List<BlogUser> listBlogUser(int blogUserId, Page page){
        Map<String, Object> params = new HashMap<>(10);
        params.put("page",page);
        return mainSqlSession.selectList(NAMESPACE + "listBlogUser", params);
    }

    public int countBlogUser(){
        Map<String, Object> params = new HashMap<>(10);
        return mainSqlSession.selectOne(NAMESPACE + "totalBlogUser",params);
    }

    public void updateBlogUser(BlogUser blogUser){
        mainSqlSession.update(NAMESPACE + "updateBlogUser", blogUser);
    }

}
